<?php
/**
 * 签到表模型
 */
namespace app\admin\model;

use app\admin\model\MySqlite;

class SignBak extends MySqlite
{
    public function __construct($tablename = '')
    {
        parent::__construct();
        if ($tablename) {
            $this->tablename = $tablename;
        } else {
            $this->tablename = uncamelize(basename(__CLASS__));
        }
    }

    public function dataList($where = '')
    {
        $sql = "select member_id,truename,phone,organization,memberType,feeType,isPay,money,receiptNumber,status,badge,token from $this->tablename $where;";
        // echo $sql;
        // exit;
        return $this->select($sql);
    }

    public function getOneById($id, $tablename = '')
    {
        $sql = "SELECT * FROM `$this->tablename` WHERE `member_id`=$id;";
        $result = $this->query($sql);
        $data = $result->fetchArray(SQLITE3_ASSOC);

        return $data;
    }

    public function updateById($data)
    {
        $id = $data['id'];
        unset($data['id']);
        $columns = "";
        foreach ($data as $key => $value) {
            $columns .= "`" . $key . "`='" . $value ."',";
        }
        $columns = rtrim($columns, ',');
        $sql = "UPDATE `$this->tablename` SET $columns WHERE `member_id`=$id";
        return $this->exec($sql);
    }

    /**
     * deleteByIds
     */
    public function deleteById($id)
    {
        if (is_array($id)) {
            $sql = "DELETE FROM `$this->tablename` WHERE `member_id` IN(";
            for ($i=0; $i < count($id); $i++) {
                $sql .= $id[$i] . ',';
            }
            $sql = rtrim($sql, ',');
            $sql .= ");";
        } else {
            $sql = "DELETE FROM `$this->tablename` WHERE `member_id`=$id;";
        }
        return $this->exec($sql);
    }
}
